package gui;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
@SuppressWarnings("serial")
public class Screen extends JFrame{
	JTextArea serverMessage;
	JList<String> fileList;
	public Screen(){
		try{
			run();
		}catch (Exception e){
			System.out.println("Something went wrong!");
		}
	}
	
	public void run() throws Exception{
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("Wazzup");
		this.setSize(450,450);
		this.setResizable(false);

		this.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		
		JTextField searchtext = new JTextField();
		searchtext.setPreferredSize( new Dimension (400, 27));
		c.fill = GridBagConstraints.HORIZONTAL;
		c.weightx = 1.;
		c.gridwidth = 1;
		c.gridx = 0;
		c.gridy = 0;
		this.add(searchtext, c);
		
		JButton search = new JButton("Search");
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 1;
		c.gridy = 0;
		this.add(search, c);
	
		JScrollPane scrill = new JScrollPane(fileList);
		scrill.setPreferredSize(new Dimension(this.getWidth(), 300));
		scrill.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 0;
		c.gridy = 1;
		c.gridwidth = 2;
		this.add(scrill, c);
		
		serverMessage = new JTextArea();
		JScrollPane scroll = new JScrollPane(serverMessage);
		scroll.setPreferredSize(new Dimension(this.getWidth(), 150));
		scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 0;
		c.gridy = 2;
		c.gridwidth = 2;
		this.add(scroll, c);
		
		this.pack();
		this.setVisible(true);


		
	}
	public void toWindow(String s){
		serverMessage.append(s);
	}
}
